﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Search.Administration;
using Umbrella.Whs;

namespace Umbrella.Whs.SharePoint
{
    public abstract class SharePointConnected
    {
        private InstallationManager _instMgr = new InstallationManager();

        protected SPFarm Farm
        {
            get { return SPFarm.Local; }
        }

        public Version SharePointVersion
        {
            get { return this.Farm.BuildVersion; }
        }

        /*protected SPAdministrationService AdministrationService
        {
            get
            {
                return this.Farm.Services.GetValue<SPAdministrationService>("SPAdmin");
            }
        }*/

        protected SPDatabaseService DatabaseService
        {
            get
            {
                return this.Farm.Services.GetValue<SPDatabaseService>();
            }
        }

        protected SPSearchService SearchService
        {
            get
            {
                return this.Farm.Services.GetValue<SPSearchService>("SPSearch");
            }
        }

        /*protected SPWindowsService WindowsService
        {
            get
            {
                return this.Farm.Services.GetValue<SPWindowsService>();
            }
        }*/

        protected SPDiagnosticsService DiagnosticsService
        {
            get
            {
                return this.Farm.Services.GetValue<SPDiagnosticsService>();
            }
        }

        protected SPIncomingEmailService IncomingEmailService
        {
            get
            {
                return this.Farm.Services.GetValue<SPIncomingEmailService>();
            }
        }

        protected SPOutboundMailService OutboundMailService
        {
            get
            {
                return this.Farm.Services.GetValue<SPOutboundMailService>();
            }
        }

        protected SPTimerService TimerService
        {
            get
            {
                return this.Farm.Services.GetValue<SPTimerService>("SPTimerV3");
            }
        }

        protected SPWebService WebService
        {
            get
            {
                return this.Farm.Services.GetValue<SPWebService>();
            }
        }

        public void CheckIsAdministrator()
        {
            if (!this.Farm.CurrentUserIsAdministrator())
                throw new InvalidOperationException("current user is not an administrator");
        }

        public SharePointConnected()
        {
        }
    }
}
